<script setup lang="ts">
onLaunch(async () => {
  // #ifdef MP-WEIXIN
  const userStore = useUserStore()
  // token 过期时间小于5分钟时，重新登录
  if (!userStore.token || !userStore.tokenExpire || userStore.tokenExpire < Date.now() + 1000 * 60 * 5) {
    console.log('====未登录，使用微信code自动登录===')
    const loginRes = await uni.login({
      provider: 'weixin',
    })
    await userStore.loginWithCode(loginRes.code).catch((err) => {
      // 这里处理自动登录失败情况，比如这里登录失败就跳转到登录页
      console.error(`登录失败，code ${err.code} , msg : ${err.message || err}`)
      nextTick(() => {
        uni.navigateTo({
          url: '/pages/login/index',
        })
      })
    })
  }
  // #endif
})
</script>

<style lang="scss">
.page-wraper {
  min-height: calc(100vh - var(--window-top));
  box-sizing: border-box;
  background: #f9f9f9;
}

.wot-theme-dark.page-wraper {
  background: #222;
}
</style>
